package src.com.bjsxt.memento.jike;

import lombok.Data;

import java.util.HashMap;

public class Originator {

    private HashMap<String, String> state;

    public Originator() {
        state = new HashMap();

    }

    /**
     * 创建备份
     * @return MementoIF
     */
    public MementoIF createMemento() {
        return new Memento(state);
    }

    /**
     * 恢复备忘
     * @param memento MementoIF
     */
    public void restoreMemento(MementoIF memento) {
        state = ((Memento) memento).getState();
    }

    /**
     * 打印
     */
    public void showState() {
        System.out.println("now state:" + state.toString());
    }

    /**
     * 测试对象1
     */
    public void testState1() {
        state.put("blood", "500");
        state.put("progress", "gate1 end");
        state.put("enemy", "5");

    }

    /**
     * 测试对象1
     */
    public void testState2() {
        state.put("blood", "450");
        state.put("progress", "gate3 start");
        state.put("enemy", "3");

    }

    @Data
    private class Memento implements MementoIF {

        private HashMap<String, String> state;

        private Memento(HashMap state) {
            this.state = new HashMap(state);
        }

    }
}
